package Interpreter;

public class OptionalNode implements DBNode {
    private String option;
    private String optionName;
    private String sourceDB;
    private DBNode fromNode = new FromNode();
    @Override
    public void intperpret(Context context) throws Exception {
        option = context.currentToken();
        switch (option) {
            case "VIEW":
                optionName = "view";
                break;
            case "Table":
                optionName = "move";
                break;
            default:
                throw new Exception("The option " + option + " has not yet been implemented");
        }
        sourceDB = context.nextToken();
        if(sourceDB.equals("FROM")) {
            sourceDB = "";
        } else {
            context.nextToken();
        }
        fromNode.intperpret(context);
    }
    @Override
    public String toString() {
        return optionName + sourceDB + fromNode.toString();
    }
}
